Memory management typically seeks to provide ways to dynamically and efficiently allocate memory space to a program, and free memory space for reuse when the data taking up these parts is no longer required by that program.
In the context of the present specification, “memory” generally refers to Random-Access-Memory (RAM), unless specifically indicated otherwise.
Incorrectly managing memory allocations may lead to memory leak. Memory leak occurs when memory is used up by data which is no longer required and is not released for future use.
Garbage collection is a memory management method aimed at avoiding memory leaks, that involves identifying objects in memory that are no longer required by the running program or programs (hereinafter—unnecessary objects) and freeing memory space in which these objects are found for reuse. Basically, garbage collection is an automated method. Garbage collection typically uses significant processing time and resources.
The most commonly used method of garbage collection is tracing garbage collection. This method involves tracing objects in memory which are called or otherwise reached by a reference or a chain of references from other objects (“root objects”) in the memory. Objects which are not referenced by root objects are considered garbage and are collected (e.g., memory is freed). Various algorithms are known for tracing garbage collection.